package com.tsinghua.discharge.controller;

import com.tsinghua.discharge.common.ServerResponse;
import com.tsinghua.discharge.service.UploadDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/upload")
public class UploadDataController {
    @Autowired
    UploadDataService uploadDataService;

    @RequestMapping(value = "/regiondata.do",method = RequestMethod.POST)
    public ServerResponse uploadRegionData(@RequestParam("file") MultipartFile file, HttpSession session){
        ServerResponse result;
        try {
            result = uploadDataService.uploadRegionData(file,session);
        } catch (Exception e) {
            e.printStackTrace();
            return ServerResponse.createByErrorMessage("上传失败");
        }
        return result;
    }
    @RequestMapping(value = "/gcamdata.do/{supSector}",method = RequestMethod.POST)
    public ServerResponse uploadModelResult(@RequestParam("file") MultipartFile file, HttpSession session,@PathVariable("supSector") String supSector){
        ServerResponse result;
        try {
            result = uploadDataService.uploadModelResult(file,session, supSector);
        } catch (Exception e) {
            e.printStackTrace();
            return ServerResponse.createByErrorMessage("上传失败");
        }
        return result;
    }
    @RequestMapping(value = "/gcammapping.do/{supSector}",method = RequestMethod.POST)
    public ServerResponse uploadGcamMapping(@RequestParam("file") MultipartFile file, HttpSession session,@PathVariable("supSector") String supSector
                                            ){
        ServerResponse result;
        try {
            result = uploadDataService.uploadGCAMMapping(file,session, supSector);
        } catch (Exception e) {
            e.printStackTrace();
            return ServerResponse.createByErrorMessage("上传失败");
        }
        return result;
    }
    @RequestMapping(value = "/thudata.do/{supSector}",method = RequestMethod.POST)
    public ServerResponse uploadThuData(@RequestParam("file") MultipartFile file, HttpSession session,@PathVariable("supSector") String supSector){
        ServerResponse result;
        try {
            result = uploadDataService.uploadThuData(file,session, supSector);
        } catch (Exception e) {
            e.printStackTrace();
            return ServerResponse.createByErrorMessage("上传失败");
        }
        return result;
    }
    @RequestMapping(value = "/thumapp.do/{supSector}",method = RequestMethod.POST)
    public ServerResponse uploadThuMapping(@RequestParam("file") MultipartFile file, HttpSession session,@PathVariable("supSector") String supSector){
        ServerResponse result;
        try {
            result = uploadDataService.uploadThuMapping(file,session, supSector);
        } catch (Exception e) {
            e.printStackTrace();
            return ServerResponse.createByErrorMessage("上传失败");
        }
        return result;
    }

    //单独展示活动水平
    @RequestMapping(value = "/techdata.do", method = RequestMethod.POST)
    public ServerResponse uploadExcelTech(@RequestParam("file") MultipartFile file, HttpSession session) {
        ServerResponse result;
        try {
            result = uploadDataService.uploadExcelTech(file, session);
        } catch (Exception e) {
            e.printStackTrace();
            return ServerResponse.createByErrorMessage("上传失败");
        }
        return result;
    }
}
